import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from '@/stores'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/', component: () => import('@/views/login/index.vue') },
    { path: '/login', component: () => import('@/views/login/index.vue') },
    //学生系统
    {
      path: '/student/',
      component: () => import('@/views/Student/Navigation.vue'),
      children: [
        { path: '', component: () => import('@/views/Student/ProjectApproval/MyContent.vue') },
        {
          path: 'content',
          component: () => import('@/views/Student/ProjectApproval/MyContent.vue')
        },
        {
          path: 'personal',
          component: () => import('@/views/Student/PersonalCenter/Personal.vue'),
          children: [
            {
              path: '',
              component: () =>
                import('@/views/Student/PersonalCenter/PersonalAssembly/PersonalInformation.vue')
            },
            {
              path: 'information',
              component: () =>
                import('@/views/Student/PersonalCenter/PersonalAssembly/PersonalInformation.vue')
            },
            {
              path: 'changePassword',
              component: () =>
                import('@/views/Student/PersonalCenter/PersonalAssembly/ChangePassword.vue')
            }
          ]
        },
        {
          path: 'filling',
          component: () => import('@/views/Student/ProjectApproval/FillingContent.vue'),
          children: [
            {
              path: '',
              component: () =>
                import('@/views/Student/ProjectApproval/Progress/BasicInformation.vue')
            },
            {
              path: 'basic',
              component: () =>
                import('@/views/Student/ProjectApproval/Progress/BasicInformation.vue')
            },
            {
              path: 'personnel',
              component: () =>
                import('@/views/Student/ProjectApproval/Progress/PersonnelInformation.vue')
            },
            {
              path: 'project',
              component: () => import('@/views/Student/ProjectApproval/Progress/ProjectBasis.vue')
            },
            {
              path: 'budget',
              component: () => import('@/views/Student/ProjectApproval/Progress/ProjectBudget.vue')
            }
          ]
        }
      ]
    },
    //管理员系统
    {
      path: '/administrators',
      component: () => import('@/views/Administrators/Navigation.vue'),
      children: [
        { path: '', component: () => import('@/views/Administrators/PlatformManagement.vue') },
        {
          path: 'platform',
          component: () => import('@/views/Administrators/PlatformManagement.vue')
        },
        {
          path: 'addpeople',
          component: () => import('@/views/Administrators/AddPeople.vue')
        },
        {
          path: 'grouping',
          component: () => import('@/views/Administrators/ProjectManagement/AssignGroups.vue')
        },
        {
          path: 'review',
          component: () => import('@/views/Administrators/ProjectManagement/ReviewStatus.vue')
        },
        {
          path: 'examine',
          component: () => import('@/views/Administrators/ProjectManagement/ReviewProject.vue')
        },
        {
          path: 'number',
          component: () => import('@/views/Administrators/ProjectManagement/NumberManagement.vue')
        },
        {
          path: 'adjustment',
          component: () => import('@/views/Administrators/ProjectManagement/ProjectAdjustment.vue')
        },
        {
          path: 'report',
          component: () => import('@/views/Administrators/ProjectManagement/ProjectSubmission.vue')
        },
        {
          path: 'personal',
          component: () => import('@/views/Administrators/PersonalCenter/Personal.vue'),
          children: [
            {
              path: '',
              component: () =>
                import(
                  '@/views/Administrators/PersonalCenter/PersonalAssembly/PersonalInformation.vue'
                )
            },
            {
              path: 'information',
              component: () =>
                import(
                  '@/views/Administrators/PersonalCenter/PersonalAssembly/PersonalInformation.vue'
                )
            },
            {
              path: 'changePassword',
              component: () =>
                import('@/views/Administrators/PersonalCenter/PersonalAssembly/ChangePassword.vue')
            }
          ]
        },
        {
          path: 'information',
          component: () => import('@/views/Administrators/ProjectInformation/index.vue'),
          children: [
            {
              path: '',
              component: () =>
                import('@/views/Administrators/ProjectInformation/Details/BasicInformation.vue')
            },
            {
              path: 'basix',
              component: () =>
                import('@/views/Administrators/ProjectInformation/Details/BasicInformation.vue')
            },
            {
              path: 'members',
              component: () =>
                import('@/views/Administrators/ProjectInformation/Details/ProjectMembers.vue')
            },
            {
              path: 'basis',
              component: () =>
                import('@/views/Administrators/ProjectInformation/Details/ProjectBasis.vue')
            },
            {
              path: 'budget',
              component: () =>
                import('@/views/Administrators/ProjectInformation/Details/Budget.vue')
            },
            {
              path: 'attachment',
              component: () =>
                import('@/views/Administrators/ProjectInformation/Details/ProjectAttachments.vue')
            },
            {
              path: 'comment',
              component: () =>
                import('@/views/Administrators/ProjectInformation/Details/ReviewComments.vue')
            },
            {
              path: 'status',
              component: () =>
                import('@/views/Administrators/ProjectInformation/Details/ProjectStatus.vue')
            }
          ]
        }
      ]
    },
    //老师系统
    {
      path: '/teacher',
      component: () => import('@/views/Teacher/Navigation.vue'),
      children: [
        {
          path: '',
          component: () => import('@/views/Teacher/MyStudents.vue')
        },
        {
          path: 'mstudent',
          component: () => import('@/views/Teacher/MyStudents.vue')
        },
        {
          path: 'stuproject',
          component: () => import('@/views/Teacher/StudentProject.vue')
        },
        {
          path: 'personal',
          component: () => import('@/views/Teacher/PersonalCenter/Personal.vue'),
          children: [
            {
              path: '',
              component: () =>
                import('@/views/Teacher/PersonalCenter/PersonalAssembly/PersonalInformation.vue')
            },
            {
              path: 'information',
              component: () =>
                import('@/views/Teacher/PersonalCenter/PersonalAssembly/PersonalInformation.vue')
            },
            {
              path: 'changePassword',
              component: () =>
                import('@/views/Teacher/PersonalCenter/PersonalAssembly/ChangePassword.vue')
            }
          ]
        }
      ]
    },

    //测试类
    { path: '/text', component: () => import('@/views/TestingCategory/login/index.vue') },
    { path: '/tx1', component: () => import('@/views/TestingCategory/TX1/tx1.vue') },
    { path: '/tx2', component: () => import('@/views/TestingCategory/TX1/tx2.vue') }
  ]
})

// 登录访问拦截
router.beforeEach((to) => {
  const userStore = useUserStore()
  if (!userStore.token && to.path !== '/login') return '/login'
})

export default router
